#include <string>
#include <chrono>
#include <iostream>

class TimerGuard {
 public:
    TimerGuard() {
        start_ = std::chrono::high_resolution_clock::now();
    }

    explicit TimerGuard(std::string name, int file_line = 0, const std::string file = "")
        : name_(name), file_line_(file_line), file_name_(file) {
        start_ = std::chrono::high_resolution_clock::now();
    }

    ~TimerGuard() {
        auto end = std::chrono::high_resolution_clock::now();
        std::chrono::duration<double, std::milli> elapsed = end - start_;
        std::cout << "time elapsed " << elapsed.count() << " ms, name " << name_ << ", at " << file_name_ << ":" << file_line_ << std::endl;
    }

 private:
    std::chrono::high_resolution_clock::time_point start_;
    std::string name_;
    int file_line_;
    std::string file_name_;
};

#define TIME_GUARD(name) TimerGuard name##_(#name, __LINE__, __FILE__);
